package com.kamloo.stg.adapter;

import java.util.ArrayList;
import android.content.Context;
import android.view.*;
import android.widget.*;
import com.kamloo.stg.data.db.Node;
import com.kamloo.stg.data.db.Stop;
import com.kamloo.stg.R;

public class TabBookmarkArrayAdapter extends ArrayAdapter<String> implements Filterable
{
	//----- GLOBAL VARIABLES -----
	private String[] values;
	private ArrayList<Node> m_nodes;
	private ArrayList<Stop> m_stops;
	private ArrayList<String> m_lines;
	private ArrayList<String> m_directions;
    
    //----- CLASS CODE -----
	public TabBookmarkArrayAdapter(Context context, String[] values, ArrayList<Stop> stops, ArrayList<Node> nodes,
								   ArrayList<String> lines, ArrayList<String> directions) 
	{
		super(context, R.layout.tab_bus_row, values);		
		 
		this.values = values.clone();
		this.m_nodes = nodes;
		this.m_stops = stops;
		this.m_lines = lines;
		this.m_directions = directions;
	}
		
	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);   
	   
	    if (m_stops != null)
	    {
	    	View rowView = inflater.inflate(R.layout.tab_bookmarks_row, parent, false);
		    // View
		    TextView numberView = (TextView) rowView.findViewById(R.id.tabBookmarkRowNumber);
		    TextView lineView = (TextView) rowView.findViewById(R.id.tabBookmarkRowLineNumber);
		    TextView directionView = (TextView) rowView.findViewById(R.id.tabBookmarkRowLineDirection);
		    TextView nameView = (TextView) rowView.findViewById(R.id.tabBookmarkRowName);
		    TextView nodeIdView = (TextView) rowView.findViewById(R.id.tabBookmarkRowNodeId);

	    	// Set visible data		    
		    lineView.append(" " + m_lines.get(position));
		    directionView.append(" " + m_directions.get(position));
		    
	    	numberView.setText(Integer.toString(m_stops.get(position).getId()));
		    nameView.setText(values[position]);
		    nodeIdView.setText(Integer.toString(m_nodes.get(position).getId()));
		    
		    return rowView;
	    }
	    
	    return null;
	}	
}
